Skip to content

RuntimeLibcalls: Move __stack_chk_fail config to tablegen #148789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented Jul 15, 2025

No description provided.

@arsenm arsenm marked this pull request as ready for review July 15, 2025 06:59
@llvmbot
Copy link
Member

llvmbot commented Jul 15, 2025

@llvm/pr-subscribers-tablegen
@llvm/pr-subscribers-llvm-ir

@llvm/pr-subscribers-backend-arm

Author: Matt Arsenault (arsenm)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/148789.diff

2 Files Affected:

  • (modified) llvm/include/llvm/IR/RuntimeLibcalls.td (+21-11)
  • (modified) llvm/lib/IR/RuntimeLibcalls.cpp (-4)
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.td b/llvm/include/llvm/IR/RuntimeLibcalls.td
index af339e2a55cf2..4d7d0fbd1a511 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.td
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.td
@@ -18,6 +18,7 @@ class DuplicateLibcallImplWithPrefix<RuntimeLibcallImpl Impl, string prefix>
 /// Libcall Predicates
 def isOSDarwin : RuntimeLibcallPredicate<"TT.isOSDarwin()">;
 def isOSOpenBSD : RuntimeLibcallPredicate<"TT.isOSOpenBSD()">;
+def isNotOSOpenBSD : RuntimeLibcallPredicate<"!TT.isOSOpenBSD()">;
 def isOSWindows : RuntimeLibcallPredicate<"TT.isOSWindows()">;
 def isNotOSWindows : RuntimeLibcallPredicate<"!TT.isOSWindows()">;
 def isNotOSMSVCRT : RuntimeLibcallPredicate<"!TT.isOSMSVCRT()">;
@@ -698,9 +699,6 @@ foreach lc = LibCalls__atomic in {
   def __#!tolower(!cast<string>(lc)) : RuntimeLibcallImpl<lc>;
 }
 
-// Stack Protector Fail
-def __stack_chk_fail : RuntimeLibcallImpl<STACKPROTECTOR_CHECK_FAIL>;
-
 // Deoptimization
 def __llvm_deoptimize : RuntimeLibcallImpl<DEOPTIMIZE>;
 
@@ -945,6 +943,9 @@ def exp10l_f80 : RuntimeLibcallImpl<EXP10_F80, "exp10l">;
 def exp10l_f128 : RuntimeLibcallImpl<EXP10_F128, "exp10l">;
 def exp10l_ppcf128 : RuntimeLibcallImpl<EXP10_PPCF128, "exp10l">;
 
+// Stack Protector Fail
+def __stack_chk_fail : RuntimeLibcallImpl<STACKPROTECTOR_CHECK_FAIL>;
+
 //--------------------------------------------------------------------
 // compiler-rt/libgcc but 64-bit only, not available by default
 //--------------------------------------------------------------------
@@ -1128,6 +1129,7 @@ defvar LibmHasLdexpF80 = LibcallImpls<(add ldexp_f80), isNotOSWindowsOrIsCygwinM
 defvar LibmHasFrexpF128 = LibcallImpls<(add frexp_f128), isNotOSWindowsOrIsCygwinMinGW>;
 defvar LibmHasLdexpF128 = LibcallImpls<(add ldexp_f128), isNotOSWindowsOrIsCygwinMinGW>;
 
+defvar has__stack_chk_fail = LibcallImpls<(add __stack_chk_fail), isNotOSOpenBSD>;
 
 //===----------------------------------------------------------------------===//
 // Objective-C Runtime Libcalls
@@ -1205,7 +1207,8 @@ def AArch64SystemLibrary : SystemRuntimeLibrary<
        LibcallImpls<(add bzero), isOSDarwin>,
        DarwinExp10, DarwinSinCosStret,
        LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
-       LibmHasExp10F32, LibmHasExp10F64, LibmHasExp10F128)
+       LibmHasExp10F32, LibmHasExp10F64, LibmHasExp10F128,
+       has__stack_chk_fail)
 >;
 
 // Prepend a # to every name
@@ -1481,7 +1484,8 @@ def ARMSystemLibrary
            // Use divmod compiler-rt calls for iOS 5.0 and later.
            LibcallImpls<(add __divmodsi4, __udivmodsi4),
                         RuntimeLibcallPredicate<[{TT.isOSBinFormatMachO() &&
-                                                  (!TT.isiOS() || !TT.isOSVersionLT(5, 0))}]>>)> {
+                                                  (!TT.isiOS() || !TT.isOSVersionLT(5, 0))}]>>,
+           has__stack_chk_fail)> {
   let DefaultLibcallCallingConv = LibcallCallingConv<[{
      (!TT.isOSDarwin() && !TT.isiOS() && !TT.isWatchOS() && !TT.isDriverKit()) ?
         (FloatABI == FloatABI::Hard ? CallingConv::ARM_AAPCS_VFP
@@ -1976,7 +1980,8 @@ def PPCSystemLibrary
            LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
            LibmHasSinCosPPCF128,
            AvailableIf<memcpy, isNotAIX>,
-           LibcallImpls<(add Int128RTLibcalls), isPPC64>)>;
+           LibcallImpls<(add Int128RTLibcalls), isPPC64>,
+           has__stack_chk_fail)>;
 
 //===----------------------------------------------------------------------===//
 // RISCV Runtime Libcalls
@@ -1990,7 +1995,8 @@ def RISCVSystemLibrary
       (add DefaultRuntimeLibcallImpls,
            exp10f, exp10, exp10l_f128,
            __riscv_flush_icache,
-           LibcallImpls<(add Int128RTLibcalls), isRISCV64>)>;
+           LibcallImpls<(add Int128RTLibcalls), isRISCV64>,
+           has__stack_chk_fail)>;
 
 //===----------------------------------------------------------------------===//
 // SPARC Runtime Libcalls
@@ -2057,7 +2063,8 @@ def SPARCSystemLibrary
             sparc_umul, sparc_div, sparc_udiv, sparc_rem, sparc_urem,
        LibcallImpls<(add _Q_qtoll, _Q_qtoull, _Q_lltoq, _Q_ulltoq), isSPARC32>,
        LibcallImpls<(add SPARC64_MulDivCalls, Int128RTLibcalls), isSPARC64>,
-       LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128)
+       LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
+       has__stack_chk_fail)
 >;
 
 //===----------------------------------------------------------------------===//
@@ -2106,7 +2113,8 @@ defvar X86CommonLibcalls =
        LibcallImpls<(add MostPowI), isNotOSMSVCRT>,
        // FIXME: MSVCRT doesn't have powi. The f128 case is added as a
        // hack for one test relying on it.
-       __powitf2_f128
+       __powitf2_f128,
+       has__stack_chk_fail
 );
 
 defvar Windows32DivRemMulCalls =
@@ -2251,7 +2259,8 @@ def WasmSystemLibrary
       (add DefaultRuntimeLibcallImpls, Int128RTLibcalls,
            CompilerRTOnlyInt64Libcalls, CompilerRTOnlyInt128Libcalls,
            exp10f, exp10,
-           emscripten_return_address)>;
+           emscripten_return_address,
+           __stack_chk_fail)>;
 
 //===----------------------------------------------------------------------===//
 // Legacy Default Runtime Libcalls
@@ -2274,5 +2283,6 @@ def LegacyDefaultSystemLibrary
          LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
          exp10f, exp10, exp10l_f128,
          __powisf2, __powidf2, __powitf2_f128,
-         LibcallImpls<(add Int128RTLibcalls), isArch64Bit>
+         LibcallImpls<(add Int128RTLibcalls), isArch64Bit>,
+         has__stack_chk_fail
 )>;
diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp
index 8ca31dff900cb..12aa9dc8d3943 100644
--- a/llvm/lib/IR/RuntimeLibcalls.cpp
+++ b/llvm/lib/IR/RuntimeLibcalls.cpp
@@ -77,10 +77,6 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
       setLibcallImpl(RTLIB::UNWIND_RESUME, RTLIB::_Unwind_SjLj_Resume);
   }
 
-  if (TT.isOSOpenBSD()) {
-    setLibcallImpl(RTLIB::STACKPROTECTOR_CHECK_FAIL, RTLIB::Unsupported);
-  }
-
   if (TT.isARM() || TT.isThumb()) {
     setARMLibcallNames(*this, TT, FloatABI, EABIVersion);
     return;

@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/move-_stack_chk_fail-tablegen branch from d9e08a6 to 4717482 Compare July 15, 2025 07:14
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/remove-darwin-half-convert-libcall-case branch from 39867e3 to b5bbf7f Compare July 15, 2025 07:21
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/move-_stack_chk_fail-tablegen branch from 4717482 to 407ba2c Compare July 15, 2025 07:22
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/move-_stack_chk_fail-tablegen branch from 407ba2c to 7bf2a69 Compare July 28, 2025 02:43
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/remove-darwin-half-convert-libcall-case branch from b5bbf7f to 0b21d22 Compare July 28, 2025 02:43
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/move-_stack_chk_fail-tablegen branch from 7bf2a69 to dfa00ac Compare July 28, 2025 03:05
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/move-_stack_chk_fail-tablegen branch from dfa00ac to 960cd88 Compare August 3, 2025 00:41
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/remove-darwin-half-convert-libcall-case branch from 0b21d22 to 9404c93 Compare August 3, 2025 00:41
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/move-_stack_chk_fail-tablegen branch from 960cd88 to a6d0dbe Compare August 3, 2025 16:32
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/remove-darwin-half-convert-libcall-case branch from 9404c93 to 20a6035 Compare August 3, 2025 16:32
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/move-_stack_chk_fail-tablegen branch from a6d0dbe to 919deef Compare August 3, 2025 23:54
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/remove-darwin-half-convert-libcall-case branch 9 times, most recently from bd93ef9 to 0c1bb90 Compare August 4, 2025 02:00
Base automatically changed from users/arsenm/runtime-libcalls/remove-darwin-half-convert-libcall-case to main August 4, 2025 02:06
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/move-_stack_chk_fail-tablegen branch 2 times, most recently from fd401dd to a2730b8 Compare August 4, 2025 02:49
Copy link
Contributor Author

arsenm commented Aug 4, 2025

Merge activity

  • Aug 4, 2:50 AM UTC: Graphite rebased this pull request as part of a merge.
  • Aug 4, 3:05 AM UTC: Graphite rebased this pull request as part of a merge.
  • Aug 4, 3:20 AM UTC: Graphite rebased this pull request as part of a merge.
  • Aug 4, 4:02 AM UTC: @arsenm merged this pull request with Graphite.

@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/move-_stack_chk_fail-tablegen branch from a2730b8 to 5ff344f Compare August 4, 2025 03:04
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/move-_stack_chk_fail-tablegen branch from 5ff344f to 9346233 Compare August 4, 2025 03:20
@arsenm arsenm merged commit 5478da9 into main Aug 4, 2025
9 checks passed
@arsenm arsenm deleted the users/arsenm/runtime-libcalls/move-_stack_chk_fail-tablegen branch August 4, 2025 04:02
@mstorsjo
Copy link
Member

mstorsjo commented Aug 5, 2025

This broke compiling for arm64ec mingw (https://github.com/mstorsjo/llvm-mingw/actions/runs/16738033027/job/47380762274):

void other(void *ptr);
void func(void) {
    char buf[10];
    other(buf);
}
$ clang -target arm64ec-windows-gnu -c stacksmash-repro.c -fstack-protector-strong
fatal error: error in backend: unsupported library call operation

CC @cjacek @efriedma-quic

@arsenm
Copy link
Contributor Author

arsenm commented Aug 5, 2025

This broke compiling for arm64ec mingw (https://github.com/mstorsjo/llvm-mingw/actions/runs/16738033027/job/47380762274):

#152116

krishna2803 pushed a commit to krishna2803/llvm-project that referenced this pull request Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants